<template>
    <div class="pt44">
        <div class="weui-cells weui-cells_form">
            <div class="weui-cell">
                <div id="old-password_panel" class="title_panel" style="display: none; opacity: 0; top: 32px;">
                    <div class="weui-cell_hd">
                        <label class="weui-label">原密码</label>
                    </div>
                </div>
                <div class="weui-cell__bd weui-cell_primary">
                    <div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset">
                        <div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset"><input v-model="oldPassword" @input="checkisSubimt" class="weui-input" type="password" placeholder="请输入原密码"></div>
                    </div>
                </div>
            </div>
            <div class="weui-cell">
                <div id="password_new_panel" class="title_panel">
                    <div class="weui-cell_hd">
                        <label class="weui-label">新登录密码</label>
                    </div>
                </div>
                <div class="weui-cell__bd weui-cell_primary">
                    <div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset">
                        <div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset"><input v-model="newPassword1" @input="checkisSubimt" class="weui-input" type="password" placeholder="请输入新密码"></div>
                    </div>
                </div>
            </div>
            <div class="weui-cell">
                <div id="password_new2_panel" class="title_panel">
                    <div class="weui-cell_hd">
                        <label class="weui-label">再次输入密码</label>
                    </div>
                </div>
                <div class="weui-cell__bd weui-cell_primary">
                    <div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset">
                        <div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset"><input v-model="newPassword2" @input="checkisSubimt" class="weui-input" type="password" placeholder="再次输入密码"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="page__bd page__bd_spacing">
            <a @click="submitChange" href="javascript:;" v-bind:class="{'weui-btn_disabled':noSubmit}" class="weui-btn weui-btn_primary ui-link">提交</a>
        </div>
    </div>
</template>

<script>
var tic = require("../components/titleInput.js");
import { Logout } from "../components/logout.js";
var logoutObject = new Logout();

export default  {
    name: 'ChangePassword',  // 组件名称
    data () {  // 数据
        return {
          msg: 'ChangePassword',
          noSubmit:true,
          oldPassword:"",
          newPassword1:"",
          newPassword2:""
        }
    },
    methods:{ // 自定义方法，可对data进行处理
        checkisSubimt(){
            if(this.oldPassword =="" || this.newPassword1 == "" || this.newPassword2 == ""){
                this.noSubmit=true;
            }else{
                this.noSubmit=false;
            }
        },
        submitChange(){
            if(this.newPassword1 != this.newPassword2){
                this.$store.state.errorMsg = "两次输入的密码不一致,请重新输入";
            }else if(this.newPassword1.length<5){
                this.$store.state.errorMsg = "密码长度至少6位";
            }else{
                var _this = this;
                var parameter = {
                    oldPassWord:this.oldPassword,
                    newPassWord:this.newPassword1,
                    newPassword2:this.newPassword2,
                    token:this.$store.state.token,
                    loginName:this.$store.state.loginName,
                    bizLicNo:this.$store.state.loginName,
                    openid:this.$store.state.openid,
                    loginType:"1"
                }
                $.post(ModifyMerPw_URL,parameter,function(cpdata) {
                    if(cpdata.lfq_merextrainfo_response && cpdata.lfq_merextrainfo_response.resp_code == "0000"){
                        _this.$store.state.errorMsg = "修改密码成功,3秒后将登出";
                        setTimeout(function() {
                            logoutObject._removeSessionStorage();
                            logoutObject.setLocalStorageLogout();
                            location.href = LoginInit_URL;
                        }, 3000);
                    }else if(cpdata.lfq_merextrainfo_response && cpdata.lfq_merextrainfo_response.resp_msg){
                        _this.$store.state.errorMsg = cpdata.lfq_merextrainfo_response.resp_msg;
                    }
                })
            }
        }
    },
    mounted:function  () {
        tic.titileInputInit();
    }
}
</script>

<style lang='scss' scoped>
@import "../assets/scss/components/_panelweui-cell.scss";

.weui-cells.weui-cells_form {
    margin-top: 0;
}
</style>
